package com.taotao.portal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.pojo.TbItem;
import com.taotao.portal.service.ItemService;

@Controller
public class ItemController {
	@Autowired
	private ItemService itemService;

	/**
	 * 返回商品基本信息给逻辑视图item.jsp
	 * 
	 * @param itemId
	 * @param model
	 * @return
	 * @author: JSJ
	 */
	@RequestMapping("/item/{itemId}")
	public String getItemById(@PathVariable long itemId, Model model) {
		TbItem item = itemService.getItemById(itemId);
		model.addAttribute("item", item);
		return "item";
	}

	/**
	 * 返回商品描述数据拼装的html给页面
	 * 
	 * @param itemId
	 * @return
	 * @author: JSJ
	 */
	@RequestMapping(value = "/item/desc/{itemId}", produces = MediaType.TEXT_HTML_VALUE
			+ ";charset=utf-8")
	@ResponseBody
	public String getItemDescById(@PathVariable long itemId) {
		String desc = itemService.getItemDescById(itemId);
		return desc;
	}
    /**
     * 返回商品规格参数数据拼装的html给页面
     * @param itemId
     * @return
     * @author: JSJ
     */
	@RequestMapping(value = "/item/param/{itemId}", produces = MediaType.TEXT_HTML_VALUE
			+ ";charset=utf-8")
	@ResponseBody
	public String getItemParamByItemId(@PathVariable long itemId) {
		String itemParam = itemService.getItemParamByItemId(itemId);
		return itemParam;
	}
}
